package com.j283_5.wisdom_park.controller.warning_record;


import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.j283_5.wisdom_park.common.result.ResultData;
import com.j283_5.wisdom_park.service.MaintenanceRecordService;
import com.j283_5.wisdom_park.service.WarningRecordService;
import com.j283_5.wisdom_park.vo.device_management.DeviceInformationVo;
import com.j283_5.wisdom_park.vo.maintenance_management.MaintenanceDeliveryVo;
import com.j283_5.wisdom_park.vo.warning_management.WarningDeliveryVo;
import com.j283_5.wisdom_park.vo.warning_management.WarningVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.ibatis.annotations.Param;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import javax.websocket.server.PathParam;
import java.sql.Timestamp;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author laoda
 * @since 2022-04-28
 */
@Transactional
@RestController
@RequestMapping("/warning")
@Api(value = "预警记录管理",tags = "预警记录管理",produces="王银伟")
public class WarningRecordController {

    @Resource
    private WarningRecordService warningRecordService;
    @Resource
    private MaintenanceRecordService maintenanceRecordService;

    @RequestMapping(value = "/warningRecord" , method = RequestMethod.POST)
    @ApiOperation(value = "查询所有预警信息",notes = "查询所有预警信息（分页）",produces="王银伟", response = ResultData.class)
    public ResultData warningRecordList(@Param("page") Page<WarningVo> page, @Param("warning") WarningVo warningVo){
        //将需要模糊查询的条件存储到map中
        Map<String,Object> map = new HashMap();

        List<WarningVo> warningVoList = warningRecordService.queryWarningSum(page, warningVo,0);

        if (!(warningVoList != null && warningVoList.size() > 0)){
            return ResultData.error();
        }

        Integer sum = warningRecordService.queryWarningCount(warningVo,0);
        map.put("warningVoList",warningVoList);
        map.put("sum",sum);
        return ResultData.ok().data(map);
    }

    @RequestMapping(value = "/warningDetails" , method = RequestMethod.POST)
    @ApiOperation(value = "查询预警详细信息",notes = "查询预警详细信息",produces="王银伟", response = ResultData.class)
    public ResultData warningDetails(Integer wdetId){
        return ResultData.ok().data(warningRecordService.queryWarningDelivery(wdetId));
    }

    @RequestMapping(value = "/warningDelete" , method = RequestMethod.POST)
    @ApiOperation(value = "删除预警信息",notes = "删除预警信息以及批量删除",produces="王银伟", response = ResultData.class)
    public ResultData warningDelete(@RequestBody ArrayList<Integer> warningIdList){
        if (warningRecordService.deleteWarning(warningIdList)){
            return ResultData.ok().data("删除成功");
        }
        return ResultData.error().message("删除失败");
    }
//
//    @RequestMapping(value = "/warningDelivery" , method = RequestMethod.POST)
//    @ApiOperation(value = "查询派送预警详情信息",notes = "查询派送预警详情信息",produces="王银伟", response = ResultData.class)
//    public ResultData warningDelivery(Integer wrecId){
//        return ResultData.ok().data(warningRecordService.queryWarningDelivery(wrecId));
//    }
    @RequestMapping(value = "/warningDeliveryUpload" , method = RequestMethod.POST)
    @ApiOperation(value = "派送预警信息",notes = "派送预警信息",produces="王银伟", response = ResultData.class)
    public ResultData warningDeliveryUpload(Integer wrecId,Integer adminId){
        if (warningRecordService.warningDelivery(wrecId, adminId)){
            return ResultData.ok().data("派送成功");
        }
        return ResultData.error().message("派送失败");
    }

    @RequestMapping(value = "/warningAddMaintenance" , method = RequestMethod.POST)
    @ApiOperation(value = "添加运维信息",notes = "添加运维信息",produces="王银伟", response = ResultData.class)
    public ResultData warningAddMaintenance(@Param("maintenanceDeliveryVo") MaintenanceDeliveryVo maintenanceDeliveryVo,Integer wrecId){
        if (maintenanceRecordService.addMaintenanceDelivery(maintenanceDeliveryVo,wrecId)){
            return ResultData.ok().data("派送成功");
        }
        return ResultData.error().message("派送失败");
    }
}

